package com.zjt.service;

import com.zjt.dao.factory.IFactoryInfoDao;
import com.zjt.dao.product.IProductInfoDao;
import com.zjt.entity.factory.FactoryInfo;
import com.zjt.utils.DateUtil;
import com.zjt.web.api.vo.base.PageVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 企业的Service interface;
 * 
 * @author xueyanbeijing
 */
@Component
public class FactoryService implements IFactoryService {
    private static Logger logger = LoggerFactory.getLogger(FactoryService.class);
    private IFactoryInfoDao factoryInfoDao;
    private IProductInfoDao productInfoDao;
    @Autowired
    public void setFactoryInfoDao(IFactoryInfoDao factoryInfoDao) {
        this.factoryInfoDao = factoryInfoDao;
    }
    @Autowired
    public void setProductInfoDao(IProductInfoDao productInfoDao) {
        this.productInfoDao = productInfoDao;
    }

    @Override
    public FactoryInfo getFactoryListByProductId(long productId) {
        return this.factoryInfoDao.findOne(productId);
    }

    @Override
    public FactoryInfo getFactoryInfoByProductName(String productName) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<FactoryInfo> getFactoryListByBrandCategory(long brandCategoryId) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<FactoryInfo> getFactoryListByBrand(long brandId) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<FactoryInfo> getFactoryListByBrandName(String brandName) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public FactoryInfo saveFactoryInfo(String chName, String enName, String contact, String tel, String httpweb,
                                       String email, String address, String shopDesctiption, String extension,
                                       int flag) {
        FactoryInfo factoryInfo = new FactoryInfo();
        factoryInfo.setChName(chName);
        factoryInfo.setEnName(enName);
        factoryInfo.setContact(contact);
        factoryInfo.setTel(tel);
        factoryInfo.setHttpweb(httpweb);
        factoryInfo.setEmail(email);
        factoryInfo.setAddress(address);
        factoryInfo.setShopDescription(shopDesctiption);
        factoryInfo.setExtension(extension);
        factoryInfo.setEnableFlag("Y");
        factoryInfo.setCreateDate(DateUtil.getCurrentDate());
        factoryInfo.setUpdateDate(DateUtil.getCurrentDate());
        factoryInfo = this.factoryInfoDao.save(factoryInfo);
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public int countFactoryByProductId(long productId) {
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public int countFactoryByBarandCategory(long brandCategoryId) {
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public int countFactoryByBrand(long brandId) {
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public FactoryInfo getFactoryInfoById(long factoryId) {
        return this.factoryInfoDao.findOne(factoryId);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Page<FactoryInfo> getFactoryInfoList(PageVO pageVO) {
        PageRequest pageRequest = new PageRequest(pageVO.getPageNo(),pageVO.getPageSize());
        Page<FactoryInfo> pageList = null;
        pageList = this.factoryInfoDao.findAll(pageRequest);
        return pageList;  //To change body of implemented methods use File | Settings | File Templates.

    }
}
